package nc.vo.ic.m4c.check;

import nc.vo.ic.m4c.entity.SaleOutBodyVO;
import nc.vo.ic.m4c.entity.SaleOutVO;
import nc.vo.ic.pub.check.UFDoubleCheckType;
import nc.vo.ic.pub.check.VOCheckUtil;
import nc.vo.ic.pub.util.NCBaseTypeUtils;
import nc.vo.ic.pub.util.ValueCheckUtil;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;



























public class SaleOutCheck
{
  public void checkNotNull(SaleOutVO bill) throws BusinessException {
    String[] headfields = { "ccustomerid", "cbiztype", "cfanaceorgoid", "cfanaceorgvid", "creceivfinorgoid", "creceivfinorgvid" };



    
//    String[] bodyfields = { "cinvoicecustid", "ccurrencyid", "corigcurrencyid", "norigprice", "norignetprice", "norigtaxprice", "norigtaxnetprice", "csourcetype", "csourcetranstype", "csourcebillhid", "csourcebillbid", "cfirsttype", "cfirsttranstype", "cfirstbillhid", "cfirstbillbid", "ctaxcodeid" };
    String[] bodyfields = { "cinvoicecustid", "ccurrencyid", "corigcurrencyid", "csourcetype", "csourcetranstype", "csourcebillhid", "csourcebillbid", "cfirsttype", "cfirsttranstype", "cfirstbillhid", "cfirstbillbid", "ctaxcodeid" };








    
    String[] addMbodyFields = { "ccurrencyid", "corigcurrencyid" };

    
    VOCheckUtil.checkHeadNotNullFields(bill, headfields);
    SaleOutBodyVO body = bill.getBody(0);
    
    if (NCBaseTypeUtils.isNull(body.getCsourcebillhid())) {
      VOCheckUtil.checkBodyNotNullFields(bill, addMbodyFields);
    }
    else {
      
      VOCheckUtil.checkBodyNotNullFields(bill, bodyfields);
    } 
  }



  
  public void checkRetNum(SaleOutVO bill) throws BusinessException {
    if (ValueCheckUtil.isTrue(bill.getHead().getBoutretflag()) || 
      ValueCheckUtil.isTrue(bill.getHead().getFreplenishflag())) {
      VOCheckUtil.checkBodyNum(bill.getBodys(), new String[] { "nshouldnum", "nshouldassistnum", "nnum", "nassistnum" }, UFDoubleCheckType.LeZero, 

          
          NCLangRes4VoTransl.getNCLangRes().getStrByID("4008003_0", "04008003-0139"));
    }
  }



  
  public void checkSaleOutVO(SaleOutVO[] bills) throws BusinessException {
    String[] samefields = { "csourcetype", "cfirsttype" };

    
    for (SaleOutVO bill : bills) {
      checkNotNull(bill);
      VOCheckUtil.checkBodySameFields(bill.getBodys(), samefields);
      checkRetNum(bill);
    } 
  }
}
